home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Other Langs
/
MacPerl ƒ
/
Perl Source ƒ
/
Perl
/
t
/
mac
/
Chat.t
< prev
next >
Wrap
Text File
|
1993-10-24
|
2KB
|
60 lines
#!/usr/local/bin/perl
require "macchat.pl";
$family = &MacPerl'Pick("Choose a socket family", "Unix", "Appletalk", "TCP/IP", "PPC")
|| die "You didn't specify a socket family !";
$server = answer("Who are you ?", "Server", "Client");
if ($family eq "Unix") {
$family = &GUSI'AF_UNIX;
$addr = &MacPerl'Choose($family, 0, "", "", $server ? &GUSI'CHOOSE_NEW : 0)
|| &GUSI'pack_sockaddr_un($family, "MacChat");
} elsif ($family eq "Appletalk") {
$family = &GUSI'AF_APPLETALK;
$addr =
&MacPerl'Choose($family, 0, "Address ?",
&GUSI'pack_sa_constr_atlk("MacChat"),
$server ? &GUSI'CHOOSE_NEW : 0);
unless ($addr) {
$addr = &GUSI'pack_sockaddr_atlk_sym(&GUSI'ATALK_SYMADDR, "MacChat", "MacChat", "*");
}
} elsif ($family eq "TCP/IP") {
$family = &GUSI'AF_INET;
$addr = ($server ? 0 : (ask("Host ?") || die "You refused to specify a host !"));
$port = ask("Port ?") || die "You refused to specify a port number !";
$addr = &GUSI'pack_sockaddr_in($family, $addr, $port);
} elsif ($family eq "PPC") {
$family = &GUSI'AF_PPC;
}
if ($server) {
&macchat'open_listen($family, $addr) || die "Opening failed";
&macchat'print("Welcome to this chat server.\n");
} else {
&macchat'open_port($family, $addr) || die "Opening failed";
}
print "?\n";
while (<>) {
if (/wr (.*)/) {
&macchat'print("$1\n");
} elsif (/rd/) {
&macchat'expect(10,
'.|\n', q{print $macchat'thisbuf; undef $macchat'S},
'TIMEOUT', q{print "Timed out !\n"; undef $macchat'S});
} elsif (/q/) {
last;
} else {
print "Valid commands are:\n";
print " rd - Read a line.\n";
print " wr text - Write a line.\n";
print " q - Quit.\n";
}
print "\n?\n";
}
print "\nHave a nice day.\n";